﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Runtime.InteropServices;

namespace Teigha.Core
{
	public class OdPsPlotStylesMap : IDisposable, IDictionary<string, OdPsPlotStyle>, ICollection<KeyValuePair<string, OdPsPlotStyle>>, IEnumerable<KeyValuePair<string, OdPsPlotStyle>>, IEnumerable
	{
		[EditorBrowsable(EditorBrowsableState.Never)]
		public OdPsPlotStylesMap(IntPtr cPtr, bool cMemoryOwn)
		{
			this.swigCMemOwn = cMemoryOwn;
			this.swigCPtr = new HandleRef(this, cPtr);
		}

		[EditorBrowsable(EditorBrowsableState.Never)]
		public static HandleRef getCPtr(OdPsPlotStylesMap obj)
		{
			if (obj != null)
			{
				return obj.swigCPtr;
			}
			return new HandleRef(null, IntPtr.Zero);
		}

		~OdPsPlotStylesMap()
		{
			this.Dispose();
		}

		public virtual void Dispose()
		{
			if (this.swigCPtr.Handle != IntPtr.Zero)
			{
				if (this.swigCMemOwn)
				{
					lock (this.locker)
					{
						if (this.swigCPtr.Handle != IntPtr.Zero && this.swigCMemOwn)
						{
							this.swigCMemOwn = false;
							GlobalsPINVOKE.delete_OdPsPlotStylesMap(this.swigCPtr);
						}
					}
					this.swigCMemOwn = false;
				}
				this.swigCPtr = new HandleRef(null, IntPtr.Zero);
			}
			GC.SuppressFinalize(this);
		}

		public OdPsPlotStyle this[string key]
		{
			get
			{
				return this.getitem(key);
			}
			set
			{
				this.setitem(key, value);
			}
		}

		public bool TryGetValue(string key, out OdPsPlotStyle value)
		{
			if (this.ContainsKey(key))
			{
				value = this[key];
				return true;
			}
			value = null;
			return false;
		}

		public int Count
		{
			get
			{
				return (int)this.size();
			}
		}

		public bool IsReadOnly
		{
			get
			{
				return false;
			}
		}

		public ICollection<string> Keys
		{
			get
			{
				ICollection<string> collection = new List<string>();
				int count = this.Count;
				if (count > 0)
				{
					IntPtr swigiterator = this.create_iterator_begin();
					for (int i = 0; i < count; i++)
					{
						collection.Add(this.get_next_key(swigiterator));
					}
					this.destroy_iterator(swigiterator);
				}
				return collection;
			}
		}

		public ICollection<OdPsPlotStyle> Values
		{
			get
			{
				ICollection<OdPsPlotStyle> collection = new List<OdPsPlotStyle>();
				foreach (KeyValuePair<string, OdPsPlotStyle> keyValuePair in this)
				{
					collection.Add(keyValuePair.Value);
				}
				return collection;
			}
		}

		public void Add(KeyValuePair<string, OdPsPlotStyle> item)
		{
			this.Add(item.Key, item.Value);
		}

		public bool Remove(KeyValuePair<string, OdPsPlotStyle> item)
		{
			return this.Contains(item) && this.Remove(item.Key);
		}

		public bool Contains(KeyValuePair<string, OdPsPlotStyle> item)
		{
			return this[item.Key] == item.Value;
		}

		public void CopyTo(KeyValuePair<string, OdPsPlotStyle>[] array)
		{
			this.CopyTo(array, 0);
		}

		public void CopyTo(KeyValuePair<string, OdPsPlotStyle>[] array, int arrayIndex)
		{
			if (array == null)
			{
				throw new System.ArgumentNullException("array");
			}
			if (arrayIndex < 0)
			{
				throw new ArgumentOutOfRangeException("arrayIndex", "Value is less than zero");
			}
			if (array.Rank > 1)
			{
				throw new ArgumentException("Multi dimensional array.", "array");
			}
			if (arrayIndex + this.Count > array.Length)
			{
				throw new ArgumentException("Number of elements to copy is too large.");
			}
			IList<string> list = new List<string>(this.Keys);
			for (int i = 0; i < list.Count; i++)
			{
				string key = list[i];
				array.SetValue(new KeyValuePair<string, OdPsPlotStyle>(key, this[key]), arrayIndex + i);
			}
		}

		IEnumerator<KeyValuePair<string, OdPsPlotStyle>> IEnumerable<KeyValuePair<string, OdPsPlotStyle>>.GetEnumerator()
		{
			return new OdPsPlotStylesMap.OdPsPlotStylesMapEnumerator(this);
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return new OdPsPlotStylesMap.OdPsPlotStylesMapEnumerator(this);
		}

		public OdPsPlotStylesMap.OdPsPlotStylesMapEnumerator GetEnumerator()
		{
			return new OdPsPlotStylesMap.OdPsPlotStylesMapEnumerator(this);
		}

		public OdPsPlotStylesMap() : this(GlobalsPINVOKE.new_OdPsPlotStylesMap__SWIG_0(), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public OdPsPlotStylesMap(OdPsPlotStylesMap other) : this(GlobalsPINVOKE.new_OdPsPlotStylesMap__SWIG_1(OdPsPlotStylesMap.getCPtr(other)), true)
		{
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private uint size()
		{
			uint result = GlobalsPINVOKE.OdPsPlotStylesMap_size(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public bool empty()
		{
			bool result = GlobalsPINVOKE.OdPsPlotStylesMap_empty(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void Clear()
		{
			GlobalsPINVOKE.OdPsPlotStylesMap_Clear(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private OdPsPlotStyle getitem(string key)
		{
			MemoryManager memoryManager = MemoryManager.GetMemoryManager();
			MemoryTransaction currentTransaction = memoryManager.GetCurrentTransaction();
			IntPtr p = GlobalsPINVOKE.OdPsPlotStylesMap_getitem(this.swigCPtr, key);
			OdPsPlotStyle result;
			if (currentTransaction != null)
			{
				currentTransaction.AddObject((OdPsPlotStyle)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true));
				result = (OdPsPlotStyle)Teigha.Core.Helpers.odrxCreateObjectInternal(p, false);
			}
			else
			{
				result = (OdPsPlotStyle)Teigha.Core.Helpers.odrxCreateObjectInternal(p, true);
			}
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private void setitem(string key, OdPsPlotStyle x)
		{
			GlobalsPINVOKE.OdPsPlotStylesMap_setitem(this.swigCPtr, key, OdPsPlotStyle.getCPtr(x));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public bool ContainsKey(string key)
		{
			bool result = GlobalsPINVOKE.OdPsPlotStylesMap_ContainsKey(this.swigCPtr, key);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		public void Add(string key, OdPsPlotStyle val)
		{
			GlobalsPINVOKE.OdPsPlotStylesMap_Add(this.swigCPtr, key, OdPsPlotStyle.getCPtr(val));
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		public bool Remove(string key)
		{
			bool result = GlobalsPINVOKE.OdPsPlotStylesMap_Remove(this.swigCPtr, key);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private IntPtr create_iterator_begin()
		{
			IntPtr result = GlobalsPINVOKE.OdPsPlotStylesMap_create_iterator_begin(this.swigCPtr);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private string get_next_key(IntPtr swigiterator)
		{
			string result = GlobalsPINVOKE.OdPsPlotStylesMap_get_next_key(this.swigCPtr, swigiterator);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
			return result;
		}

		private void destroy_iterator(IntPtr swigiterator)
		{
			GlobalsPINVOKE.OdPsPlotStylesMap_destroy_iterator(this.swigCPtr, swigiterator);
			if (GlobalsPINVOKE.SWIGPendingException.Pending)
			{
				throw GlobalsPINVOKE.SWIGPendingException.Retrieve();
			}
		}

		private object locker = new object();

		private HandleRef swigCPtr;

		protected bool swigCMemOwn;

		public sealed class OdPsPlotStylesMapEnumerator : IEnumerator<KeyValuePair<string, OdPsPlotStyle>>, IDisposable, IEnumerator
		{
			public OdPsPlotStylesMapEnumerator(OdPsPlotStylesMap collection)
			{
				this.collectionRef = collection;
				this.keyCollection = new List<string>(collection.Keys);
				this.currentIndex = -1;
				this.currentObject = null;
				this.currentSize = this.collectionRef.Count;
			}

			public KeyValuePair<string, OdPsPlotStyle> Current
			{
				get
				{
					if (this.currentIndex == -1)
					{
						throw new InvalidOperationException("Enumeration not started.");
					}
					if (this.currentIndex > this.currentSize - 1)
					{
						throw new InvalidOperationException("Enumeration finished.");
					}
					if (this.currentObject == null)
					{
						throw new InvalidOperationException("Collection modified.");
					}
					return (KeyValuePair<string, OdPsPlotStyle>)this.currentObject;
				}
			}

			object IEnumerator.Current
			{
				get
				{
					return this.Current;
				}
			}

			public bool MoveNext()
			{
				int count = this.collectionRef.Count;
				bool flag = this.currentIndex + 1 < count && count == this.currentSize;
				if (flag)
				{
					this.currentIndex++;
					string key = this.keyCollection[this.currentIndex];
					this.currentObject = new KeyValuePair<string, OdPsPlotStyle>(key, this.collectionRef[key]);
				}
				else
				{
					this.currentObject = null;
				}
				return flag;
			}

			public void Reset()
			{
				this.currentIndex = -1;
				this.currentObject = null;
				if (this.collectionRef.Count != this.currentSize)
				{
					throw new InvalidOperationException("Collection modified.");
				}
			}

			public void Dispose()
			{
				this.currentIndex = -1;
				this.currentObject = null;
			}

			private OdPsPlotStylesMap collectionRef;

			private IList<string> keyCollection;

			private int currentIndex;

			private object currentObject;

			private int currentSize;
		}
	}
}
